﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;

namespace CreateChartTemplate
{
    public partial class ComboChart1_copy : Form
    {
        Series currentSeries = new Series();

        public ComboChart1_copy()
        {
            InitializeComponent();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            SaveFileDialog dlg = new SaveFileDialog();
            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                //ChartSerializer _serializer = comboChart_1.Serializer;
                //_serializer.IsTemplateMode = true;
                ChartSerializer _serializer = chartSpline.Serializer;
                _serializer.IsTemplateMode = false;
                //_serializer.Content = SerializationContents.Appearance;

                _serializer.Format = System.Windows.Forms.DataVisualization.Charting.SerializationFormat.Xml;
                _serializer.Save(dlg.FileName);
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void btnLoad_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                ChartSerializer _serializer = comboChart_1.Serializer;
                _serializer.Load(dlg.FileName);
            }
        }

        /// <summary>
        /// Mouse Down Event
        /// </summary>
        private void chart1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            // Call Hit Test Method
            HitTestResult result = comboChart_1.HitTest(e.X, e.Y);

            if (result.ChartElementType == ChartElementType.DataPoint)
            {
                currentSeries = result.Series;
            }
        }

        private void btnColors_Click(object sender, EventArgs e)
        {
            
            DialogResult result = colorDialog1.ShowDialog();
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                lblColor.Text = "Color = " + colorDialog1.Color.ToKnownColor().ToString();
                if (currentSeries.Name != null)
                {
                    currentSeries.Color = colorDialog1.Color;
                }
            }
        }

        private void ComboChart1_copy_Shown(object sender, EventArgs e)
        {
            dtDataToPlot.Rows.Add(25.3, 20, 0.3);
            dtDataToPlot.Rows.Add(31, 30, 0.4);
            dtDataToPlot.Rows.Add(22.7, 40, 0.7);
            dtDataToPlot.Rows.Add(33.4, 50, 0.6);
            dtDataToPlot.Rows.Add(36.6, 60, 0.8);
        }

    }
}
